using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Reflection;
using System.Text;
using System.Xml.Serialization;

namespace Galaktika.BI.Extensibility.Dom
{
    [XmlRoot(Namespace = Galaktika.BI.Silverlight.Common.Namespace)]
    public class BrickActionInvoker : BrickObject
    {
        public BrickActionInvoker()
        { 
        }

        public BrickActionInvoker(BrickAction action)
            : this(action, null)
        {
        }

        public BrickActionInvoker(BrickAction action, IDictionary<string, string> param)
            : base()
        {
            this.Action = action;
            if (param != null)
            {
                foreach (KeyValuePair<string, string> kv in param)
                {
                    this.Parameters.Add(new ArgumentEntry(kv.Key, kv.Value));
                }
            }
        }

        public BrickAction Action { get; set; }

        private List<ArgumentEntry> m_Params;
        [XmlArray]
        [XmlArrayItem(typeof(ArgumentEntry))]
        public List<ArgumentEntry> Parameters
        {
            get
            {
                if (m_Params == null)
                {
                    m_Params = new List<ArgumentEntry>();
                }

                return m_Params;
            }
        }
    }

    [XmlRoot(Namespace = Galaktika.BI.Silverlight.Common.Namespace)]
    public class ArgumentEntry
    {
        public ArgumentEntry()
        {
        }

        public ArgumentEntry(string name, string value)
        {
            this.Name = name;
            this.Value = value;
        }

        public string Name { get; set; }
        public string Value { get; set; }
    }
}
